package com.my.study.jvm.section3;

public class HeapAlloc {

	public static void main(String[] args) {
		System.out.print("maxMemory = ");
		System.out.println(Runtime.getRuntime().maxMemory()/1024/1024+" Mb");
		System.out.print("free mem = ");
		System.out.println(Runtime.getRuntime().freeMemory()/1024/1024+" Mb");
		System.out.print("total mem = ");
		System.out.println(Runtime.getRuntime().totalMemory()/1024/1024+" Mb");
		
		byte[] b = new byte[1*1024*1024];
		System.out.println("分配了1M的空间给数组");
		
		System.out.print("maxMemory = ");
		System.out.println(Runtime.getRuntime().maxMemory()/1024/1024+" Mb");
		System.out.print("free mem = ");
		System.out.println(Runtime.getRuntime().freeMemory()/1024/1024+" Mb");
		System.out.print("total mem = ");
		System.out.println(Runtime.getRuntime().totalMemory()/1024/1024+" Mb");
		
		b = new byte[4*1024*1024];
		System.out.println("分配了4M的空间给数组");
		
		System.out.print("maxMemory = ");
		System.out.println(Runtime.getRuntime().maxMemory()/1024/1024+" Mb");
		System.out.print("free mem = ");
		System.out.println(Runtime.getRuntime().freeMemory()/1024/1024+" Mb");
		System.out.print("total mem = ");
		System.out.println(Runtime.getRuntime().totalMemory()/1024/1024+" Mb");
		
	}
	
}
